Title: SQL BT (By-BKK) / 02 Constraints
Tags: Obsidian_to_Anki

Q: What SQL clause is used to filter results from a table?
A: WHERE

Q: True or False: The WHERE clause checks each row to decide if it should be included in the results.
A: True

Q: How do you write a select query with a constraint?
A: SELECT column FROM mytable WHERE condition;

Q: How can you join multiple constraints in a WHERE clause?
A: Using AND or OR keywords

Q: What does the SQL condition 'num_wheels >= 4 AND doors <= 2' do?
A: Finds rows with num_wheels 4 or more and doors 2 or less

Q: Which operators can be used for numerical data in SQL?
A: =, !=, <, <=, >, >=

Q: How do you check if a number is within a range in SQL?
A: Use BETWEEN … AND …

Q: What does NOT BETWEEN … AND … do in SQL?
A: Selects values not in the given range

Q: How do you check if a column value exists in a list?
A: IN (…)

Q: What does NOT IN (…) check in a SQL query?
A: Value does not exist in the given list

Q: True or False: Adding constraints can make queries faster by reducing unnecessary data.
A: True

Q: Is it required to write SQL keywords in all capital letters?
A: No, but it is a helpful convention

Q: Reverse card: WHERE
A: Which SQL clause filters results from a table?

Q: Reverse card: True
A: The WHERE clause checks each row to decide inclusion in results. True or False?

Q: Reverse card: =, !=, <, <=, >, >=
A: Which operators can be used for numerical data in SQL?

Q: Reverse card: Use BETWEEN … AND …
A: How do you check if a number is within a range in SQL?

Q: Reverse card: SELECT column FROM mytable WHERE condition;
A: How do you write a select query with a constraint?

Q: What SQL query finds the movie with id 6?
A: SELECT * FROM movies WHERE id = 6;

Q: What SQL finds movies released between 2000 and 2010?
A: SELECT * FROM movies WHERE year BETWEEN 2000 AND 2010;

Q: How do you get movies NOT released between 2000 and 2010?
A: SELECT * FROM movies WHERE year NOT BETWEEN 2000 AND 2010;

Q: How do you find the first 5 Pixar movies and their release year?
A: SELECT title, year FROM movies WHERE id <= 5;

Q: Reverse card: SELECT * FROM movies WHERE year BETWEEN 2000 AND 2010;
A: How do you find movies released between 2000 and 2010?

Q: Reverse card: SELECT * FROM movies WHERE id = 6;
A: What is the SQL query to find the movie with id 6?

Q: Reverse card: SELECT title, year FROM movies WHERE id <= 5;
A: Which SQL query finds the first 5 Pixar movies and their release year?